package com.dao.impl;

import com.dao.LoginDao;
import com.entiy.LogintableEntity;
import com.factory.HibernateFactory;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.query.Query;

public  class LoginDaoImp implements LoginDao {
    @Override
    public LogintableEntity validateUser(String login, String password) {
        Session session =  HibernateFactory.getSession();
        Transaction transaction = session.beginTransaction();
        Query query = session.createQuery("from LogintableEntity where login = ?1 and  password = ?2").setParameter(1,login).setParameter(2,password).setMaxResults(1);
        LogintableEntity logintableEntity = (LogintableEntity) query.uniqueResult();
        transaction.commit();
        session.close();
        return  logintableEntity;
    }
}
